package pattern.behavioral.Interpreter.simple;

/**
 * @author: chaoyang.ren  
 * @date:Jun 22, 2017  
 * @time:4:31:09 PM   
 * @email:chaoyang.ren@foxmail.com  
 * @version: 1.0
 */
public class Or extends Expression{
	private Expression left,right;

	public Or(Expression left, Expression right){
		this.left = left;
		this.right = right;
	}
	
	@Override
	public boolean interpret(Context ctx) {
		return left.interpret(ctx) || right.interpret(ctx);
	}

	@Override
	public boolean equals(Object obj) {
		if(obj instanceof Or && ((Or)obj).left.equals(this.left) && ((Or)obj).right.equals(this.right)){
			return true;
		}
		return false;
		
	}

	@Override
	public int hashCode() {
		return this.toString().hashCode();
		
	}

	@Override
	public String toString() {
		return "(" + left.toString() + " OR " + right.toString() + ")";
	}

}

